
package com.ffcs.crmd.tsp.admin.facade.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ctg.itrdc.platform.common.entity.PageInfo;
import com.ctg.itrdc.platform.common.utils.bean.BeanUtils;
import com.ffcs.crmd.platform.core.ddd.facade.impl.AbstractCrmDomFacade;
import com.ffcs.crmd.tsp.admin.api.dto.SliceGroupDTO;
import com.ffcs.crmd.tsp.admin.api.facade.ISliceGroupFacade;
import com.ffcs.crmd.tsp.admin.entity.SliceGroup;
import com.ffcs.crmd.tsp.admin.service.ISliceGroupService;

@Service("sliceGroupFacade")
public class SliceGroupFacadeImpl extends AbstractCrmDomFacade implements ISliceGroupFacade {
   	
   	@Autowired
	private ISliceGroupService sliceGroupService;
	   
   	@Override
    public SliceGroupDTO get(SliceGroupDTO sliceGroupDto) throws Exception {
       	 SliceGroup sliceGroup = new SliceGroup();
         BeanUtils.applyIf(sliceGroup, sliceGroupDto, false);
     
        SliceGroup rsliceGroup = sliceGroupService.get(sliceGroup);
        SliceGroupDTO rsliceGroupDTO = new SliceGroupDTO();
        BeanUtils.applyIf(rsliceGroupDTO, rsliceGroup, false);
        return rsliceGroupDTO;
    }
   	
	@Override
    public void save(SliceGroupDTO sliceGroupDto) throws Exception {
        SliceGroup sliceGroup = new SliceGroup();
        BeanUtils.applyIf(sliceGroup, sliceGroupDto, false);
        sliceGroupService.saveSliceGroup(sliceGroup);
    }
    
    @Override
    public void remove(SliceGroupDTO sliceGroupDto) throws Exception {
        SliceGroup sliceGroup = new SliceGroup();
        BeanUtils.applyIf(sliceGroup, sliceGroupDto, false);
        sliceGroupService.deleteSliceGroup(sliceGroup);
    }
    
    @Override
    public void remove(List<SliceGroupDTO> sliceGroupDtoList) throws Exception {
        List<SliceGroup> sliceGroupList = BeanUtils.copyList(sliceGroupDtoList, SliceGroup.class);
        sliceGroupService.deleteSliceGroup(sliceGroupList);
    }
    
    @Override
    public void update(SliceGroupDTO sliceGroupDto) throws Exception {
        SliceGroup sliceGroup = new SliceGroup();
        BeanUtils.applyIf(sliceGroup, sliceGroupDto, false);
        sliceGroupService.updateSliceGroup(sliceGroup);
    }


    /**
     * 功能说明:
     * 
     * @param clusterName
     * @param name
     * @param jobId
     * @return
     * @throws Exception
     */
    @Override
    public List<SliceGroupDTO> query(SliceGroupDTO sliceGroupDto) throws Exception {
        SliceGroup sliceGroup = new SliceGroup();
        BeanUtils.applyIf(sliceGroup, sliceGroupDto, false);
        
        List<SliceGroup> sliceList = sliceGroupService.query(sliceGroup);
        return BeanUtils.copyList(sliceList, SliceGroupDTO.class);
    }


    /**
     * 功能说明:
     * 
     * @param clusterName
     * @param name
     * @param jobId
     * @param pageNumber
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<SliceGroupDTO> queryPage(SliceGroupDTO sliceGroupDto) throws Exception {
        SliceGroup sliceGroup = new SliceGroup();
        BeanUtils.applyIf(sliceGroup, sliceGroupDto, false);
        
        PageInfo<SliceGroup> pageInfo = sliceGroupService.queryPage(sliceGroup, sliceGroupDto.getPageNumber(), sliceGroupDto.getPageSize());
        return copyPageInfo(pageInfo);
    }
    
    
    private PageInfo<SliceGroupDTO> copyPageInfo(PageInfo<SliceGroup> pageInfo) throws Exception{
        PageInfo<SliceGroupDTO> pageInfoDto = new PageInfo<SliceGroupDTO>();
        BeanUtils.applyIf(pageInfoDto, pageInfo, false);
        pageInfoDto.setList(BeanUtils.copyList(pageInfo.getList(), SliceGroupDTO.class));
        return pageInfoDto;
    }

}
